package game;

import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.util.LinkedList;

class Menu extends Scene
{
	Background background;
	LinkedList<GameObject> buttons = new LinkedList<GameObject>();
	GameObject currentButton;
	GameObject arrowUp, arrowDown;
	GameObject infoPanel;
	GameObject changePage;
	boolean avancar = true;
	
	int[] btnIndex = {2, 1, 0};
	int[] panelIndex = {8, 7, 6};
	int count = 2;
	
	boolean mouseReleased = true;
	
	public Menu()
	{
		background = new Background(5,new Point(0,0), new Point(180,600));
		
		arrowUp = new GameObject(new Point(51, 150), new Point(78, 68));
		arrowUp.setImage(3);
		
		currentButton = new GameObject(new Point(15, 266), new Point(150, 78));
		currentButton.setImage(btnIndex[count]);
		
		arrowDown = new GameObject(new Point(51, 382), new Point(78, 68));
		arrowDown.setImage(4);
		
		infoPanel = new GameObject(new Point(180, 0), new Point(620, 600));
		infoPanel.setImage(panelIndex[count]);
		
		changePage = new GameObject(new Point(570, 480), new Point(172, 40));
		changePage.setImage(45);
	}

	public void update()
	{
		if (Mouse.getInstance().isMousePressed(MouseEvent.BUTTON1) && mouseReleased) 
		{
			mouseReleased = false;
			if (arrowUp.getRectangle().contains(Mouse.getInstance().getPositionMouse()) && count < 2)
			{
				count++;
				currentButton.setImage(btnIndex[count]);
				infoPanel.setImage(panelIndex[count]);
			}
			
			if (arrowDown.getRectangle().contains(Mouse.getInstance().getPositionMouse()) && count > 0)
			{
				count--;
				currentButton.setImage(btnIndex[count]);
				infoPanel.setImage(panelIndex[count]);
			}
			
			if (currentButton.getRectangle().contains(Mouse.getInstance().getPositionMouse()) && count == 2)
			{
				SceneManager.changeScene(5);
			}
			
			if (count == 2)
			{
				if (changePage.getRectangle().contains(Mouse.getInstance().getPositionMouse()) && avancar)
				{
					avancar = !avancar;
					changePage.setImage(46);
					infoPanel.setImage(44);
				}
				
				else if (changePage.getRectangle().contains(Mouse.getInstance().getPositionMouse()) && !avancar)
				{
					avancar = !avancar;
					changePage.setImage(45);
					infoPanel.setImage(6);
				}
			}
		}
		if (!Mouse.getInstance().isMousePressed(MouseEvent.BUTTON1))
		{
			mouseReleased = true;
		}
		
		System.out.println("" + Mouse.getInstance().getPositionMouse());
	}

	public void draw(Graphics2D g2d)
	{
		background.draw(g2d);
		currentButton.draw(g2d);
		arrowUp.draw(g2d);
		arrowDown.draw(g2d);
		infoPanel.draw(g2d);
		if (count == 2)
			changePage.draw(g2d);
	}

	


}